package advanced.concurrent;

import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadPool_L {
    public static void main(String[] args) {
        int coreSize = 5;
        int maxSize = 10000;
        int destoryTime = 30;
        TimeUnit tu = TimeUnit.MINUTES;
        int queueLen = 100000;
        BlockingDeque queue = new LinkedBlockingDeque(queueLen);//使用双向链队来作为线程等待队列
        ThreadPoolExecutor pool = new ThreadPoolExecutor(coreSize, maxSize, destoryTime, tu, queue);
        pool.execute(() -> {
            for (int i = 0; i < 1999; i++)
                System.out.println(i + 1);
        });
        while (true) {
            try {
                if (!pool.awaitTermination(1, TimeUnit.SECONDS)) break;
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        pool.shutdown();
    }
}
